﻿using blackhouse.BlackApart.Business.Apartments;
using blackhouse.BlackApart.WebNemo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace blackhouse.StareKino.Web {
    public class CinemaActors : IEnumerable<CinemaActor> {

        #region Fields

        private List<CinemaActor> actors;

        #endregion

        #region Constructors

        public CinemaActors(IApartmentGroup apartmentType) {
            NemoApartmentType nemoGroup = apartmentType as NemoApartmentType;
            if (nemoGroup != null) {
                this.actors = nemoGroup.GetRecords<CinemaActor>("kluczowa_obsada").ToList();
            }
            else
                this.actors = new List<CinemaActor>();
        }

        #endregion

        #region Methods

        public IEnumerator<CinemaActor> GetEnumerator() {
            return this.actors.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
            return this.actors.GetEnumerator();
        }

        public override string ToString() {
            if (this.actors.Count > 0) {
                string[] displayActors = this.actors.OrderBy(ca => ca.LastName).Select(ca => ca.FirstName + " " + ca.LastName).ToArray();
                return string.Join(", ", displayActors);
            }
            else
                return String.Empty;
        }

        #endregion

    }
}